<?php


namespace app\admin\controller\member2;


use app\common\controller\Adminbase;
use think\Db;
use function form\e;

class Member extends Adminbase
{
    protected $searchFields = 'id,nickname';
    protected function initialize()
    {
        parent::initialize();
    }
    public function index(){
        if ($this->request->isAjax()) {
            list($page, $limit, $where) = $this->buildTableParames();
            $_list=Db::name('member')
                ->where($where)
                ->order('create_time desc')
                ->page($page,$limit)
                ->select();
            foreach ($_list as $k=>$v){
                $_list[$k]['create_time'] = date('Y-m-d H:i:s', $v['create_time']);
            }
            $total=Db::name('member')
                ->where($where)
                ->count();
            $result = ["code" => 0, "count" => $total, "data" => $_list];
            return json($result);
        }
        return $this->fetch();
    }
    public function edit(){
        $member_id = $this->request->param('id/d', 0);
        $data=Db::name('member')->find($member_id);
        $update=array(
            'id'=>$member_id,
            'status'=>!$data['status'],
        );
        $result=Db::name('member')->update($update);
        if ($result){
            return ['code' => 200, 'data' => '', 'msg' => '切换成功'];
        }else{
            return ['code' => 100, 'data' => '', 'msg' => '操作失败'];
        }
    }

    public function manage(){
        $member_id = $this->request->param('id/d', 0);
        $data=Db::name('member')->find($member_id);
        $update=array(
            'id'=>$member_id,
            'is_manage'=>!$data['is_manage'],
        );
        $result=Db::name('member')->update($update);
        if ($result){
            return ['code' => 200, 'data' => '', 'msg' => '设置成功'];
        }else{
            return ['code' => 100, 'data' => '', 'msg' => '操作失败'];
        }

    }
}